package cn.belong.jk.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import cn.belong.jk.entity.Contract;
import cn.belong.jk.entity.ContractVO;
import cn.belong.jk.service.ContractService;
import cn.belong.jk.util.ContractPrint;

@Controller
@RequestMapping("contract")
public class ContractController extends BaseController {

	@Resource
	private ContractService contractService;
	
    @RequestMapping("/list.action")  
    public String list(Model model){  
        List<Contract> datalist=contractService.find(null);  
        model.addAttribute("datalist",datalist);  
      
        return "/cargo/contract/jContractList.jsp";  
    }  
    
  //跳到添加编辑页面  
    @RequestMapping("/tocreate.action")  
    public String tocreate(){  
        return "/cargo/contract/jContractCreate.jsp";  
    }  

    //添加  
    @RequestMapping("/insert.action")  
    public String insert(Contract contract){  
        contractService.insert(contract);  
          
        return "redirect:/contract/list.action";  
    }  
    
  //跳转到编辑页面  
    @RequestMapping("/toupdate.action")  
    public String toupdate(String id,Model model){  
        Contract obj=contractService.get(id);  
        model.addAttribute("obj",obj);  
          
        return "/cargo/contract/jContractUpdate.jsp";  
    }  
      
      
    //修改方法  
    @RequestMapping("/update.action")  
    public String update(Contract contract){  
        contractService.update(contract);  
          
        return "redirect:/contract/list.action";  
    }  
    
  //删除方法  
    @RequestMapping("/delete.action")  
    public String delete(@RequestParam("id") String[] ids){  
        contractService.delete(ids);  
          
        return "redirect:/contract/list.action";  
    }  
    
    //查看  
    @RequestMapping("/toview.action")  
    public String toview(String id,Model model){  
    	ContractVO obj=contractService.view(id);  
        model.addAttribute("obj",obj);  
        return "/cargo/contract/jContractView.jsp";  
    }
    
 
    
  //上报  
    @RequestMapping("/submit.action")  
    public String submit(String[] id){  
        contractService.submit(id);  
          
        return "redirect:/contract/list.action";  
    }  
      
      
    //取消  
    @RequestMapping("/cancel.action")  
    public String cancel(String[] id){  
        contractService.cancel(id);  
          
        return "redirect:/contract/list.action";  
    }  
    
	//打印
	@RequestMapping("/print.action")
	public void print(String id, HttpServletRequest request, HttpServletResponse response) throws Exception{
		ContractPrint cp = new ContractPrint();
		
		ContractVO obj = contractService.view(id);
		cp.print(obj, request.getSession().getServletContext().getRealPath("/"), response);
	}
}
